// 获取Json数据
var SideBarData;
$(document).ready(function(){
    $.ajax({
        url : "/MES/Resources/AllItems.json",
        datatype: "json",
        success : function(data) {
            SideBarData = data;
            SiderPage();
        }
    });
});

// 侧边栏
function SiderPage() {
    var str = "";
    var strul = "";
    for (var i = 0; i < SideBarData.length; i++) {
        str += "<li id='" + i + "' class='has-sub 'onclick='ChangeStyle("+i+")' >"
            + "<a>"
            //添加CSS
            + "<i class='" + SideBarData[i].CSS + "'></i>"
            + "<span class='title'>" + SideBarData[i].Title + "</span>"
            + "</a>"
            + "</li>"
    }
    $("#main-menu").append(str);
    for (var i = 0; i < SideBarData.length; i++) {
        for (var j = 0; j < SideBarData[i].Children.length; j++) {
            strul = "<ul>"
                + "<li id='" + SideBarData[i].Children[j].URL + "'>"
                + "<a>"
                + "<span class='title'>" + SideBarData[i].Children[j].Title + "</span>"
                + "</a>"
                + "</li>"
                + "</ul>"
            $("#" + i).append(strul);
        }
    }
}

//改变列表的样式
function  ChangeStyle(ulnum){
    //执行页面样式的切换
    var e = window.event;
    fatherid = e.path[1].id;
    //如果点击到其他元素，跳过操作
    if(fatherid == ""){
        return;
    }
    //如果id不是数字,显示对应的页面
    var n = Number(fatherid);
    if (isNaN(n)){
        //iFrame替换新页面
        $("#FatherFame").attr("src", fatherid + '.jsp');
        return;
    }
    if($("#"+ulnum).hasClass("has-sub ")){
        $("#"+ulnum).attr("class","has-sub expanded");
        $("#"+ulnum).find("ul").attr("style","display:block;");
    }else{
        $("#"+ulnum).attr("class","has-sub ");
        $("#"+ulnum).find("ul").attr("style","display:none;");
    }
}

